//
//  BookManager.m
//  OC03_homeWork
//
//  Created by Hanlingyu on 16/7/6.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "BookManager.h"

@implementation BookManager

- (void)addBook:(Book *)book {
    [self.bookArray addObject:book];
}

- (void)removeBookWithBookName:(NSString *)bookName {
    BOOL isHave = NO;
    for (int i = 0; i < self.bookArray.count; i++) {
        Book *book = self.bookArray[i];
        if ([book.bookName isEqualToString:bookName]) {
            NSLog(@"已找到");
            [self.bookArray removeObjectAtIndex:i];
            isHave = YES;
        } 
    }
    if (isHave == NO) {
        NSLog(@"对不起, 没有找到该书籍");
    }
}

- (void)reviseBookWithBookName:(NSString *)bookName revisePrice:(float)reviePrice {
    BOOL isHave = NO;
    for (int i = 0; i < self.bookArray.count; i++) {
        Book *book = self.bookArray[i];
        if ([book.bookName isEqualToString:bookName]) {
            NSLog(@"已找到");
            [self.bookArray removeObjectAtIndex:i];
            Book *modificationBook = [Book bookWithBookName:bookName price:reviePrice];
            [self.bookArray insertObject:modificationBook atIndex:i];
        }
    }
    if (isHave == NO) {
        NSLog(@"对不起, 没有找到该书籍");
    }
}

- (void)outPutOfAllBookName {
    NSMutableArray *bookNameArray = [NSMutableArray array];
    for (int i = 0; i < self.bookArray.count; i++) {
        Book *book = self.bookArray[i];
        NSString *bookName = book.bookName;
        [bookNameArray addObject:bookName];
    }
    NSLog(@"%@", bookNameArray);
}

@end
